package com.sjsm.sjsmscenerecord.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import com.sjsm.sjsmscenerecord.holder.BaseListHolder;

import java.util.List;

/**
 * Created by hasee on 2016/12/15.
 * 我爱敲代码!!!
 */




public abstract class BaseListAdapter<T> extends BaseAdapter {
    public List<T> list;
    public Context context;

    public BaseListAdapter(List<T> list, Context context) {
        super();
        this.list = list;
        this.context = context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // 1.初始化holder
        BaseListHolder<T> holder = null;
        if (convertView == null) {
            holder = getHolder();//需要一个不固定的holder
        } else {
            holder = (BaseListHolder) convertView.getTag();
        }
        // 3.绑定数据
        holder.bindData(list.get(position));
        return holder.getHolderView();
    }

    protected abstract BaseListHolder<T> getHolder();

}
